﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows8Accelerator.Core.Xaml.Controls.RichText;
using Windows8Accelerator.Core.Xaml.Storage;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace TextRichText
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class DemoPage2 : Page
    {
        public DemoPage2()
        {
            this.InitializeComponent();
        }

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var html = await StringLoader.GetContentAsync(@"/Assets/HTMLPage1.html", StorageLocation.InstalledLocation);
            var richTextBlockHtmlLoader = new RichTextBlockHtmlLoader();
            richTextBlockHtmlLoader.HyperlinkClick += richTextBlockHtmlLoader_HyperlinkClick;
            richTextBlockHtmlLoader.ImageClick += richTextBlockHtmlLoader_ImageClick;
            var a = new DispatcherTimer();
            a.Interval = new TimeSpan(0, 0, 10);
            a.Tick += (b,c) => {
                richTextBlockHtmlLoader.Load(RichTextBlock, html);
            };
            a.Start();
        }

        void richTextBlockHtmlLoader_ImageClick(object sender, Windows8Accelerator.Core.Xaml.Html.ImageClickEventArgs e)
        {
            //e.Handled = true;
        }

        void richTextBlockHtmlLoader_HyperlinkClick(object sender, Windows8Accelerator.Core.Xaml.Html.HyperlinkClickEventArgs e)
        {
            //e.Handled = true;
        }
    }
}
